<template>
  <footer class="footer">
    <div class="footer-container">
      <!-- 左侧：Logo和版权 -->
      <div class="footer-left">
        <img src="@/assets/image/header.jpg" alt="公司Logo" class="footer-logo" />
        <div class="footer-copyright">Copyright©2022 佳博工艺品</div>
      </div>
      <!-- 中间：联系方式等信息 -->
      <div class="footer-center">
        <div>电话：+86-0577-63181888</div>
        <div>手机：15888788886</div>
        <div>邮箱：sales1@wzjiabo.com</div>
        <div>地址：浙江平阳县鳌江镇海华路136号</div>
        <div>浙ICP备11008454号 <span class="footer-link">网站地图</span></div>
      </div>
      <!-- 右侧：二维码 -->

      <div class="footer-right">
        <img src="@/assets/image/99.jpg" alt="手机二维码" class="footer-qr" />
        <div class="footer-qr-text">手机二维码</div>
      </div>
    </div>

    <!-- 移动端功能栏 -->
    <div class="mobile-action-bar" v-show="isMobile">
      <div class="action-item" @click="handleShare">
        <div class="action-icon">
          <el-icon>
            <Promotion />
          </el-icon>
        </div>
        <div class="action-label">分享</div>
      </div>
      <div class="action-item" @click="handlePhone">
        <div class="action-icon">
          <el-icon>
            <Iphone />
          </el-icon>
        </div>
        <div class="action-label">手机</div>
      </div>
      <div class="action-item" @click="handleCategory">
        <div class="action-icon">
          <el-icon>
            <Menu />
          </el-icon>
        </div>
        <div class="action-label">分类</div>
      </div>
      <div class="action-item" @click="scrollToTop">
        <div class="action-icon">
          <el-icon>
            <Top />
          </el-icon>
        </div>
        <div class="action-label">顶部</div>
      </div>
    </div>
  </footer>
</template>

<script>
export default {
  name: 'FooterIndex',
  data() {
    return {
      isMobile: false
    }
  },
  mounted() {
    this.checkDevice()
    window.addEventListener('resize', this.checkDevice)
  },
  beforeUnmount() {
    window.removeEventListener('resize', this.checkDevice)
  },
  methods: {
    checkDevice() {
      this.isMobile = window.innerWidth <= 768
    },
    handleShare() {
      // 分享功能
      if (navigator.share) {
        navigator.share({
          title: document.title,
          url: window.location.href
        }).catch(err => {
          console.log('分享失败:', err)
          this.copyToClipboard(window.location.href)
        })
      } else {
        this.copyToClipboard(window.location.href)
      }
    },
    handlePhone() {
      // 手机功能 - 显示联系方式
      this.$message({
        message: '联系电话：15888788886',
        type: 'info',
        duration: 3000
      })
    },
    handleCategory() {
      // 分类功能 - 跳转到产品页面
      this.$router.push('/products')
    },
    scrollToTop() {
      // 滚动到顶部
      window.scrollTo({
        top: 0,
        behavior: 'smooth'
      })
    },
    copyToClipboard(text) {
      if (navigator.clipboard) {
        navigator.clipboard.writeText(text).then(() => {
          this.$message({
            message: '链接已复制到剪贴板',
            type: 'success',
            duration: 2000
          })
        }).catch(() => {
          this.fallbackCopyToClipboard(text)
        })
      } else {
        this.fallbackCopyToClipboard(text)
      }
    },
    fallbackCopyToClipboard(text) {
      const textArea = document.createElement('textarea')
      textArea.value = text
      document.body.appendChild(textArea)
      textArea.select()
      try {
        document.execCommand('copy')
        this.$message({
          message: '链接已复制到剪贴板',
          type: 'success',
          duration: 2000
        })
      } catch (err) {
        this.$message({
          message: '复制失败，请手动复制链接',
          type: 'error',
          duration: 3000
        })
      }
      document.body.removeChild(textArea)
    }
  }
}
</script>

<style scoped>
.footer {
  background: #1b4e54;
  color: #fff;
  padding: 40px 0 0 0;
  width: 100%;
}

.footer-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0 40px 20px 40px;
}

.footer-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 220px;
}

.footer-logo {
  width: 120px;
  margin-bottom: 10px;
}

.footer-copyright {
  margin-top: 10px;
  font-size: 15px;
  color: #fff;
}

.footer-center {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 15px;
  min-width: 320px;
}

.footer-link {
  color: #fff;
  text-decoration: underline;
  cursor: pointer;
  margin-left: 8px;
}

.footer-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 140px;
}

.footer-qr {
  width: 110px;
  height: 110px;
  background: #fff;
  object-fit: contain;
  border-radius: 6px;
}

.footer-qr-text {
  margin-top: 10px;
  font-size: 15px;
  color: #fff;
  text-align: center;
}

@media (max-width: 900px) {
  .footer-container {
    flex-direction: column;
    align-items: center;
    gap: 30px;
  }

  .footer-left,
  .footer-center,
  .footer-right {
    align-items: center;
    min-width: unset;
  }
}

@media (max-width: 768px) {
  .footer {
    padding: 30px 0 0 0;
  }

  .footer-container {
    padding: 0 20px 20px 20px;
    gap: 25px;
  }

  .footer-left {
    min-width: unset;
    align-items: center;
  }

  .footer-logo {
    width: 100px;
  }

  .footer-copyright {
    font-size: 14px;
    text-align: center;
  }

  .footer-center {
    min-width: unset;
    text-align: center;
    gap: 8px;
  }

  .footer-center div {
    font-size: 14px;
  }

  .footer-right {
    min-width: unset;
  }

  .footer-qr {
    width: 90px;
    height: 90px;
  }

  .footer-qr-text {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .footer {
    padding: 25px 0 60px 0;
  }

  .footer-container {
    padding: 0 15px 15px 15px;
    gap: 20px;
  }

  .footer-logo {
    width: 80px;
  }

  .footer-copyright {
    font-size: 13px;
  }

  .footer-center div {
    font-size: 13px;
  }

  .footer-qr {
    width: 80px;
    height: 80px;
  }

  .footer-qr-text {
    font-size: 13px;
  }
}

/* 移动端功能栏样式 */
.mobile-action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #1b4e54;
  border-top: 1px solid #0f3a3f;
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
}

.action-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  min-height: 60px;
  color: #fff;
}

.action-item:active {
  background-color: rgba(255, 255, 255, 0.1);
  transform: scale(0.95);
}

.action-icon {
  font-size: 20px;
  margin-bottom: 4px;
  transition: transform 0.3s ease;
}

.action-label {
  font-size: 12px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

/* 为移动端功能栏腾出空间 */
@media (max-width: 768px) {
  .footer {
    padding-bottom: 60px;
  }
}

/* 超小屏幕优化 */
@media (max-width: 360px) {
  .mobile-action-bar {
    height: 55px;
  }

  .action-item {
    min-height: 55px;
    padding: 6px 2px;
  }

  .action-icon {
    font-size: 18px;
  }

  .action-label {
    font-size: 11px;
  }

  .footer {
    padding-bottom: 55px;
  }
}

/* 横屏模式优化 */
@media (max-width: 768px) and (orientation: landscape) {
  .mobile-action-bar {
    height: 50px;
  }

  .action-item {
    min-height: 50px;
    padding: 4px 2px;
  }

  .action-icon {
    font-size: 16px;
    margin-bottom: 2px;
  }

  .action-label {
    font-size: 10px;
  }

  .footer {
    padding-bottom: 50px;
  }
}
</style>
